import { Color, Matrix4, Vector3, Quaternion } from 'https://unpkg.com/three/build/three.module.js';
import { initShaders, ScaleLinear, imgPromise } from '../jsm/Utils.js';
import lib from '../jsm/ThreeLib.js';
import Poly from '../jsm/Poly3.js'
import Sky from '../jsm/Sky.js'
import ShapeGeo from '../jsm/ShapeGeo.js';
import ImageJump from '../jsm/ImageJump.js'

window.onload = function () {

    const canvas = document.getElementById("canvas");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;


    const gl = canvas.getContext("webgl");
    // //开启颜色合成,才会有透明度的感觉
    // gl.enable(gl.BLEND);
    // gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
    // //开始背景遮挡
    gl.enable(gl.DEPTH_TEST);

    //初始化着色器
    initShaders(gl,
        document.querySelector("#vertexShader").innerText,
        document.querySelector("#fragmentShader").innerText);
    lib.clearCanvas(gl, new Color("rgba(255,255,255,1)"), 1);


    // 顶点映射
    var a = 1;
    let arr = [
        -a, -a,
        -a, a,
        a, -a,
        a, a,
    ];





    let poly = new Poly({
        gl: gl,
        arr: arr,
        list: [
            { name: 'a_Position', size: 2, beginIndex: 0 },
        ],
        uniforms: {
            'u_CanvasSize': {
                type: 'uniform2fv',
                value: [canvas.width, canvas.height]
            },
            'u_Set': {
                type: 'uniform1f',
                value: 1
            }
        }
    });

    poly.draw(["TRIANGLE_STRIP"]);




    lib.getPoxels(gl, 0, 0);
    lib.getPoxels(gl, 0, 1);
    lib.getPoxels(gl, 1, 0);
    lib.getPoxels(gl, 1, 1);

    // let set = 0.0;
    // let v = 0.002;
    // let judge = false;
    // (function ani() {
    //     if (!judge) {
    //         set += v;
    //     } else {
    //         set -= v;
    //     }

    //     console.log(set)

    //     poly.uniforms['u_Set'].value = set;
    //     poly.updateUniform();
    //     poly.draw(["TRIANGLE_STRIP"]);
    //     if (set <= 0) {
    //         judge = true;
    //     } else if (set >= 2) {
    //         judge = false;
    //     }

    //     requestAnimationFrame(ani);
    // })();



};
